<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
 
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
    <script src="https://service.media.gov.cn/jmopen/jssdk/index.js"></script>
    
    <script type="text/javascript">
    
    var page = getUrlParam('page');
	if(page=="" || page==null || page=="undefined"){
		page=1;
	}
	
	var qiyemingcheng =getUrlParam('qiyemingcheng') ;			//鎼滅储鍐呭
	if(qiyemingcheng==""||qiyemingcheng==null|| qiyemingcheng =="undefined"){
		qiyemingcheng="";
	}
	
    jQuery(document).ready(function($){
	    	
	    	var page_start = page;
	    	var page_end = Number(page)+Number(2);
	    	for(var i=page_start;i<page_end;i++){
	    		console.log("caiji.html?page="+page+"&qiyemingcheng="+qiyemingcheng);
	    		search(i); 
	    		page++;
	    		setTimeout(function(){
	    		      //所有的逻辑
	    		},2000);
	    		
	    	}
	    	setTimeout('reload()',5000);
	    	
	    	 
    	}
    );

    
     
    function search(_page=1){
    	var url = "https://service.media.gov.cn/jiekou/gszj/smallandmicro/smallandmicrolist.do?";
    	var cityCode = "51";
    	var page = _page;
    	var searchText =getUrlParam('qiyemingcheng') ;			//鎼滅储鍐呭
    	if(searchText==""||searchText==null){
    		searchText="";
    	}
    	//console.log(searchText);
    	
    	var date = {
    		q:searchText,
    		organ:cityCode,
    		page:page,
    		pageSize:20
    	}
    	
    	
    	lightAppJssdk.request.request({
    		url:url,
    		header:"",
    		format:"json",
    		data:date,
    		success: function (data) {
    			if (data != null) {
    				var mlObj = data.result;
    				console.log(JSON.stringify(data));
    				var resultSize = mlObj.length;
    				if (resultSize > 0) {
    					 var jsonStr="";
    					for (var i = 0; i <resultSize; i++) {
    						//console.log(mlObj[i].entname+"   "+JSON.stringify(mlObj[i]));
    						var _mlObj = mlObj[i];
    						var entname = _mlObj.entname;
    						var regno = _mlObj.regno;
    						var cptltotal = _mlObj.cptltotal;
    						var enttype = _mlObj.enttype;
    						var regorganid = _mlObj.regorganid;
    						//console.log(entname+"   "+regno+"   "+cptltotal+"   "+enttype+regorganid);
    						if(jsonStr==""){
    							jsonStr='{"entname":"'+entname+'","regno":"'+regno+'","cptltotal":"'+cptltotal+'","enttype":"'+enttype+'","regorganid":"'+regorganid+'"}';
    						}else{
    							jsonStr=jsonStr+','+'{"entname":"'+entname+'","regno":"'+regno+'","cptltotal":"'+cptltotal+'","enttype":"'+enttype+'","regorganid":"'+regorganid+'"}';
    						}
    					}
    					jsonStr='['+jsonStr+']';
    					
    					var apidata =jsonStr  ;
    					insertqiyeku(apidata);
    					 
    					//插入数据库
    				} else {
    					 
    				}
    			} else {
    				console.log("返回数据出错")
    			}
    		},
    		failed: function (data) {
    			
    			console.log("接口请求失败");
    		}
    	})
    	
    	 
    }
    
    
    function insertqiyeku(mydata){
    	$.ajax({
    	    type: "GET",
    	    cache: false,
    	    url: "/api/qiyeku/insertqiyeku?qiyelist="+mydata,
    	    datatype: "JSON",
    	    success: function (data) {
    	    	console.log(data);
    	    },
    	    error: function (xhr, status, error) {
    	        //alert(error);
    	    	console.log("insertqiyeku error");
    	    }
    	});
    	
    }
    
    
  //获取url中的参数
    function getUrlParam(name) {
    	 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
         var r = window.location.search.substr(1).match(reg);
         if (r != null)
             return decodeURI(r[2]); // decodeURI(r[2]); 解决参数是中文时的乱码问题
  
         return null;
    }
     
    function reload(){
    	if(Number(page)>2000){
    		page=1
    	}
		window.location.href="caiji.html?page="+page+"&qiyemingcheng="+qiyemingcheng;
	}
    </script>

</head>
 <body  >
</body>
</html>